package xyz.yang.query;

import org.apache.commons.lang3.StringUtils;

import java.util.Map;
import java.util.Objects;

/**
 * @author Xuehong Yang
 * @since 1.0
 */

@SuppressWarnings("unused")
public record Field(String value) {
    public Field {
        if (StringUtils.isBlank(value)) {
            throw new IllegalArgumentException("The field could not be null or empty. ");
        }
    }

    public static Field of(String value) {
        return new Field(value);
    }

    public String value(Map<String, String> fieldMap) {
        if (Objects.isNull(fieldMap)) {
            throw new IllegalArgumentException("Map could not be null.");
        }
        return fieldMap.getOrDefault(value, value);
    }
}
